<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/2/24 0024
 * Time: 上午 10:53
 */

namespace backend\controllers;


use backend\components\BaseComponentController;
use backend\components\LanguageTemplate;
use common\components\DataHelper;
use common\models\Admin\Admin;
use common\models\MchAccount\MchAccount;
use common\models\MchRoles\MchRoles;

class CenterController extends BaseComponentController
{
    public function __construct($id, $module, $config = [])
    {
        $this->layout = self::LAYER_CONTENT;
        parent::__construct($id, $module, $config);
    }

    public function actionIndex()
    {
        $user = Admin::findOne($this->uid);
        if ( $user->isAgent() ) {
            $userInfo = $user->agentInfo;
        } else {
            $userInfo = $user->regionManagerInfo;
        }
        $this->layout = self::LAYER_CONTENT;
        return $this->render('index', [
            'user' => $user,
            'userInfo' => $userInfo
        ]);
    }

    public function actionSetInfo()
    {
        if ( Admin::setUserAccount($this->post(), Admin::getCurrentUser("type"), $this->uid) ) {
            return $this->jsonResponse(self::RESPONSE_SUCCESS);
        }
        return $this->jsonResponse(self::RESPONSE_FAILURE, Admin::error());
    }
}